import type { Lesson } from './lesson'
import http from '@/utils/http'

export interface ArragngeTemplate {
  id: string
  name: string
  lessonCount: number
  startDate: string
  endDate: string
}

export interface TimeTemplate {
  id: string
  name: string
  startTime: string
  endTime: string
}

export interface ClassInfo {
  id: string
  name: string
  classYear: number
  admissionYearLimit: number
  term: string
  grade: string
  subject: string
  classCategory: string
  classTypeId: string
  classLevelLimit: number
  campusId: string
  leadTeacherId: string
  assistTeacherId: string
  totalLessonCount: number
  completedLessonCount: number
  arrangeTemplateId: string
  timeTemplateId: string
  lessonChangeLimit: number
  totalPrice: number
  unitPrice: number
  saleStatus: number
  classStatus: number
  renewalStartTime: string
  renewalEndTime: string
  enrollStartTime: string
  image: string
  remainCount: number
}

export interface ClassStudentInfo {
  id: string
  enrollmentId: string
  classId: string
  studentId: string
  studentJoinType: number
  studentClassStatus: number
}

// 报名信息
export interface EnrollmentInfo {
  id: string
  studentId: string
  classId: string
  enrollLessonCount: number
  completedLessonCount: number
  cancelLessonCount: number
  remainClassChangeCount: number
  remainLessonChangeCount: number
  renewalClassIds: string[]
}

// 学生班级
export interface StudentClassResp extends ClassInfo {
  arrangeTemplate: ArragngeTemplate
  timeTemplate: TimeTemplate

  leadTeacherName: string
  campusName: string
}

// 报名班级
export interface EnrollClassResp extends StudentClassResp {
  enrollment: EnrollmentInfo
}

export interface EnrollClassQuery {
  studentId: string
  classStatus?: number[]
}

export interface StudentClassQuery {
  studentId: string
}

/** 课次 */
/** 选课模块-班级查询 课次详情 */
export interface ClassLessonResp extends Lesson {
  weekName: string
}

export interface SelectiveClassLesson extends ClassLessonResp {
  select: boolean
}

/** 转班调课 */
// 转班调课请求
export interface ClassChangeCreateReq {
  oldClassId: string
  newClassId: string
  studentId: string
  changeType: string
  remark?: string
  changeLessonIndexList?: number[]
  onlyRemainLesson: boolean
}

// 转班调课撤销请求
export interface ClassChangeRevertReq {
  recordId: string
}

// 转班调课记录
export interface ClassChangeQuery {
  studentId: string
}
export interface ChangeRecordResp {
  id: string
  createTime: string
  enrollmentId: string
  changeType: string
  originalClassId: string
  originalLessonIndexes: number[]
  targetClassId: string
  targetLessonIndexes: number[]
  details: string
  businessId: string
  operateSource: string
  operateStatus: string

  originalClassInfo: ClassInfo
  targetClassInfo: ClassInfo
}

// 查询课次列表
export function getClassLessonList(classId: string) {
  return http.get<ClassLessonResp[]>(`/p/class/lesson/list/${classId}`)
}

// 查询报名班级列表
export function getEnrollClassPage(query: EnrollClassQuery) {
  return http.get<Page<EnrollClassResp>>(`/p/class/getEnrollClassPage`, query)
}

// 查询学生班级列表
export const getStudentClassList = (query: StudentClassQuery) => {
  return http.get<StudentClassResp[]>(`/p/class/getStudentClassList`, query)
}

// 转班调课
export const changeClassOrLesson = (req: ClassChangeCreateReq) => {
  return http.post(`/p/class/change/create`, req)
}

// 撤销转班调课
export const revertClassChange = (req: ClassChangeRevertReq) => {
  return http.post(`/p/class/change/revert`, req)
}

// 查询转班调课记录
export const getChangeRecordPage = (query: ClassChangeQuery) => {
  return http.get<Page<ChangeRecordResp>>(`/p/class/change/page`, query)
}
